//
//  ReadFile.swift
//  WriteToLocal
//
//  Created by 郑东喜 on 2017/2/24.
//  Copyright © 2017年 郑东喜. All rights reserved.
//  读取文件

import UIKit

class ReadFile: UIViewController {
    
    
    lazy var tableView: UITableView = {
        let t : UITableView = UITableView.init(frame: self.view.bounds)
        t.delegate = self;
        t.dataSource = self;
        return t
    }()
    
    
    lazy var dataSource: NSMutableArray = {
       
        var ad : NSMutableArray = NSMutableArray()
//        ad = NSMutableArray(contentsOfFile: NSHomeDirectory() + "/Documents/folder/dic.plist")!
        
        ad = ["写文件","tabbarVC","删文件","ddd","测试网页"]
        
        return ad
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(tableView)
    }
}

extension ReadFile : UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cellID")
        
        if cell == nil {
            cell = UITableViewCell.init(style: .default, reuseIdentifier: "cellID")
        }
        
        cell?.textLabel?.text = self.dataSource[indexPath.row] as? String
        
        return cell!
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataSource.count
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
            //写文件
        case 0:
            
            DispatchQueue.main.async {
                self.navigationController?.pushViewController(ViewController(), animated: true)
            }
            
            
            break
            //tabbarvc
        case 1:
            
            DispatchQueue.main.async {
                self.navigationController?.pushViewController(TabbarVC(), animated: true)
            }
            
            break
            
            //删文件
        case 2:
            self.navigationController?.pushViewController(DelLoaclFile(), animated: true)
            break
            
        //删文件
        case 3:
            self.navigationController?.pushViewController(M3d(), animated: true)
            break
            
            //测试网页
        case 4:
            self.navigationController?.pushViewController(LocalHtml(), animated: true)
            break
        default:
            break
        }
    }
}


